#include "tcp_server.h"

tcp_server::tcp_server(QWidget *parent) : QWidget(parent)
{

}



void tcp_server::listen(quint16 port)
{
    this->server.listen(QHostAddress::Any , port);
    qDebug() << "监听启动";

    // 检测连接
    connect(&this->server , &QTcpServer::newConnection , this , [&](){

        // 接收新连接的套接字
        this->Socket = this->server.nextPendingConnection();

        qDebug() << "客户端连接成功";

        // 接收数据
        connect(this->Socket , &QTcpSocket::readyRead , this , [&](){
            QByteArray data = this->Socket->readAll();
            Msg = QString(data);
            emit recv_sig(Msg);
        });

    });
}


